<?php

/*
	info: 获取全局信息
*/

require './common.inc.php';

$webglobal['datainfo'] = $db->GetOne("SELECT * FROM promotion ORDER BY id DESC LIMIT 0,1");

if (!empty($webglobal['datainfo']))
{
	$return['data']['gift'] = array(
			'id' => $webglobal['datainfo']['id'],
			'title' => $webglobal['datainfo']['title'],
			'giftpic' => $webconfig['webimageurl'].$webglobal['datainfo']['gifpic'],
			'giftinfo' => $webglobal['datainfo']['giftinfo'],
		);
	$return['data']['member'] = null;
	$return['data']['ischeckcode'] = false;
	$return['data']['isReserved'] = false;
	if ($user['m_islogin'])
	{
		$return['data']['member'] = array(
										'uid' => $user['m_uid'],
										'truename' => $user['m_truename'],
										'email' => $user['m_email'],
										'mobile' => $user['m_mobile'],
										'weddingdate' => global_FormatTime($user['m_weddingdate'], $webglobal['weddingdatemode']),
									);
		$webglobal['codeinfo'] = $db->GetOne("SELECT U.sid,U.peoplenum,U.codetime,S.* FROM promotion_user U LEFT JOIN promotion_site S ON (U.sid=S.id) WHERE U.uid='{$user['m_uid']}' AND U.pid='{$webglobal['datainfo']['id']}'");
		if (!empty($webglobal['codeinfo']))
		{
			$return['data']['ischeckcode'] = true;
			if ($webglobal['codeinfo']['peoplenum']>0 && !empty($webglobal['codeinfo']['id']))
			{
				$return['data']['isReserved'] = true;
			}
		}
	}
	$return['data']['message'] = array('isReservedTimeOut'=>$weblang['api_isReservedTimeOut']);
	api_EchoReturn();
}
else
{
	api_EchoReturn($weblang['api_notHaveGift']);
}
